var table, laypage, laydate, layer, form, util, loaded = false, pageObj = null, listData, currentData, layerMode,element;
/**
 * 生成页头的查询表单
 * @param configs           配置
 * @param formId
 * @returns {string}
 */
var createQueryForm = function (configs, formId) {
    var str = "<div id='" + formId + "' class='layui-form-item layui-row' style='padding:0;margin:0;'>";
    str += createFormHtml(configs, true);
    str += "<div class='layui-inline layui-col-xs" + 3 + "' style='float:" + (bsConf.queryFloat ? bsConf.queryFloat : "right") + ";'>\n" +
        "            <button lay-filter='" + formId + "' class='layui-btn bs-button-query' type='button'>查询</button>\n" +
        "            <button type='reset' class='layui-btn layui-btn-primary'>重置</button>\n" +
        "        </div>";
    str += "</div>";
    if (isNotNull(formId)) {
        $('.bs-query-form').html(str);
        initSelect("#" + bsConf.queryFormId);
        $('.layui-inline').css({
            margin: '0px',
            padding: '0px',
            voName: bsConf.voName,
            paddingTop: '3px',
            paddingBottom: '3px'
        });
    }
    return str;
};

/**
 * 查询表单
 * @param url
 * @param pageNo
 * @param pageSize
 */
var queryData = function (url, pageNo, pageSize) {
    layerMode = "query";
    //高度
    var height = $(window).height();
    var tableY = $('#tableDiv').offset().top;

    loaded = false;
    var str = url + "?pageNo=" + pageNo + "&pageSize=" + pageSize;
    $('.bs-query-form .bs-input-div').each(function () {
        var name = $(this).attr('name');
        var value = getInputValue($(this));
        if (value == null) {
            value = "";
        }
        str += "&" + name + "=" + value;
    });
    if (bsConf.extendQueryParam) {
        str = bsConf.extendQueryParam(str);
    }
    table.render({
        id: bsConf.tableID,
        elem: '#tableDiv'
        , url: str
        , headers:{"token":getCookie("token")}
        , height: height - tableY - 85
        //表格的列
        , cols: [bsConf.tableCols]
        , page: false
        , response: {
            statusName: 'code',
            statusCode: 0,
            msgName: 'msg',
            countName: 'totalCount',
            dataName: "['data']['pageInfo']['list']"
        }
        , done: function (res) {
            checkLogin(res);
            //分页
            if(res['code'] != 3000)(
                laypage.render({
                    elem: 'pageDiv'
                    , curr: res.data['pageInfo']['pageNo']
                    , count: res.data['pageInfo']['totalCount']
                    , limit: res.data['pageInfo']['pageSize']
                    , groups: 10//页面10个一组显示
                    , last: false //不显示尾页
                    , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                    , jump: function (obj) {
                        pageObj = obj;
                        if (!loaded) {
                            loaded = true;
                        }
                        else {
                            queryData(url, obj.curr, obj.limit);
                        }
                    }
                })
            );
            if (!isNull(bsConf.queryCallback)) {
                bsConf.queryCallback(res);
            }
        }
    });
};

/**
 * 绑定列表操作列事件
 */
var bindTableEventCol = function () {
    table.on('tool(tableDiv)', function (obj) {
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        var tr = obj.tr; //获得当前行 tr 的DOM对象
        if (layEvent === 'del') { //删除
            deleteCurrent(data[bsConf.tableID]);
        } else if (layEvent === 'edit') { //编辑
            showUpdateLayer(data);
        } else if (layEvent === 'pauseTask') { //暂停任务
            bsConf.pauseTask && bsConf.pauseTask(data[bsConf.tableID]);
        } else if (layEvent === 'resumeTask') { //启用任务
            bsConf.resumeTask && bsConf.resumeTask(data[bsConf.tableID]);
        } else if (layEvent === 'runTask') { //立即执行任务
            bsConf.runTask && bsConf.runTask(data[bsConf.tableID]);
        }
    });
};

/**
 * 初始化之后关联全局按钮
 */
var bindButtonEvents = function () {
    //查询按钮
    $('.bs-button-query').on('click', function () {
        queryData(url, 1, pageObj == null ? 20 : pageObj.limit);
    });
    //新建实体
    $('.bs-button-create').on('click', function () {
        showCreateLayer()
    });
    //批量删除
    $('.bs-button-batch-delete').on('click', function () {
        deleteBatch();
    });

    //监听提交
    form.on('submit', function (data) {
        document.getElementById(data.form.id+"-sub-btn").setAttribute("disabled", true);
        var func = bsConf[data.form.id];
        if (isNotNull(func)) {
            func();
        }
        else {
        }
        return false;
    });
};

/**
 * 生成form中的input内容
 * @param configs
 * @param isQuery
 * @returns {string}
 */
var createFormHtml = function (configs, isQuery) {
    var defaultCols = 6;
    if (!isNull(document.getElementsByClassName('bs-query-form')[0])) {
        var realWidth = parseInt(document.getElementsByClassName('bs-query-form')[0].offsetWidth);
        defaultCols = parseInt(12 / (realWidth / 400))+1;
    }
    if (isQuery) {
        //每个查询框对应的占屏幕宽度，在config文件中配置，默认是3
        defaultCols = bsConf.queryCols ? bsConf.queryCols : defaultCols;
    }
    var str = "";
    for (var i = 0; i < configs.length; i++) {
        var config = configs[i];
        var type = config['type'];
        var label = config['label'];
        var label2= config['label2']
        var name = config['name'];
        var name2= config['name2'];
        var defaultValue = config['default'];
        defaultValue = isNull(defaultValue) ? '' : defaultValue;
        var verify = config['verify'];
        var cols = config['cols'];
        var dataUrl = config['dataUrl'];
        dataUrl = getStrFromDataMap(dataUrl);
        var idProperty = config['idProperty'];
        var nameProperty = config['nameProperty'];
        var multiple = config['multiple'];
        multiple = !isNull(multiple);
        var rows = config['rows'];
        rows = isNull(rows) ? defaultCols : rows;
        var id = config['id'];
        var readOnly = config['readOnly'];
        if (type == 'b_time'){
            rows = 2*rows;
        }
        var addClasses = "";
        if (type == 'select' && multiple) {
            addClasses = " layui-unselect layui-form-select downpanel cs";
        }
        var itemPre = "<div class='layui-inline layui-col-xsxx" + rows + "' style='margin-top:0px;margin-bottom:0px;padding:0px;" + (type == 'hidden' ? 'display:none;' : '') + "'>\n" +
            "            <label class='layui-form-label'>" + label + "</label>\n" +
            "            <div class='layui-input-inline" + addClasses + " bs-input-div' name='" + name + "' type='" + type + "' multiple2=" + multiple + " >";
        var itemTail = "</div></div>";

        if (!isQuery) {
            if (type == 'treeSelect') {
                itemPre = "<div class='layui-form-item'>\n" +
                    "                 <label class='layui-form-label'>" + label + "</label>\n" +
                    "                 <div class='layui-input-block'>";
            } else {
                itemPre = "<div class='layui-form-item'>\n" +
                    "                 <label class='layui-form-label'>" + label + "</label>\n" +
                    "                 <div id='" + id + "' class='layui-input-block" + addClasses + " bs-input-div' name='" + name + "' type='" + type + "' multiple2=" + multiple + " >";
            }
        }


        if (type == 'select' || type == 'checkbox' || type == 'radio') {
            if (isNull(cols)) {
                cols = [];
                if (isNotNull(dataUrl)) {
                    if (isNull(idProperty)) {
                        idProperty = "id";
                    }
                    if (isNull(nameProperty)) {
                        nameProperty = "name";
                    }
                    $.ajax({
                        type: 'get',
                        url: dataUrl,
                        dataType: 'json',
                        headers:{"token":getCookie("token")},
                        async: false,
                        cache: false,
                        success: function (result) {
                            checkLogin(result);
                            if (result.code == 0) {
                                for (var j = 0; j < result.data['pageInfo'].list.length; j++) {
                                    var v = result.data['pageInfo'].list[j];
                                    cols.push([v[idProperty], v[nameProperty]]);
                                }
                            }
                        }
                    });
                }
            }
        }

        var options = "";
        var checked;
        var tmp;
        if (type == 'text') {
            if (!readOnly){
                str += itemPre +
                    "            <input  lay-verify='" + verify + "' type='" + type + "' name='" + name + "' value='" + defaultValue + "' autocomplete='off' class='layui-input bs-form-input' style=''>\n" +
                    itemTail;
            }

        }
        else if (type == 'hidden') {
            str += itemPre +
                "            <input lay-verify='" + verify + "' type='" + type + "' name='" + name + "' value='" + defaultValue + "' autocomplete='off' class='layui-input bs-form-input' style=''>\n" +
                itemTail;
        }
        else if (type == 'textarea') {
            str += itemPre +
                "<textarea type='textarea' name='" + name + "' placeholder='请输入内容' class='layui-textarea bs-form-input'>" + defaultValue + "</textarea>" +
                //"            <input lay-verify='" + verify + "' type='" + type + "' name='" + name + "' value='"+ defaultValue +"' autocomplete='off' class='layui-input bs-form-input' style=''>\n" +
                itemTail;
        }
        else if (type == 'datetime' || type == 'datetimerange') {
            str += itemPre + " <input type='text' class='layui-input bs-" + type + "' id='" + name + "' name='" + name + "' value='" + defaultValue + "'>" + itemTail;
        } else if (type == 'b_time') {
            str += itemPre + " <input type='text' class='layui-input bs-datetime' id='" + name + "' name='" + name + "' placeholder='yyyy-MM-dd hh:mm:ss' autocomplete='off'> </div>"
            var itemtail = "  <label class='layui-form-label'>" + label2+ "</label>\n" +
                "<div class='layui-input-inline" + addClasses + " bs-input-div' name='" + name2 + "' type='" + type + "' multiple2=" + multiple + " >";
            str += itemtail + " <input type='text' class='layui-input bs-datetime' id='" + name2 + "' name='" + name2 + "' placeholder='yyyy-MM-dd hh:mm:ss' autocomplete='off'>"+itemTail;
        }
        else if (type == 'select') {
            if (multiple == false) {
                options = "<option value=''>请选择</option>";

                for (var j = 0; j < cols.length; j++) {
                    checked = (cols[j][0] == defaultValue);
                    options += "<option value='" + cols[j][0] + "' " + (checked ? " selected " : "") + ">" + cols[j][1] + "</option>";
                }
                str += itemPre +
                    "<select multiple='multiple' lay-omit lay-tools name='" + name + "' class='bs-form-input' lay-verify='" + verify + "' lay-search=''>\n" +
                    options + "\n" +
                    "</select>\n" +
                    itemTail;

            }
            else {
                tmp = "," + defaultValue + ",";
                //针对多选的下拉-----start  视个人情况而定，需要加这段代码在config文件中增加参数multipleSelect:true
                if (!isQuery && bsConf.hasMultipleSelect) {
                    tmp = ",";
                    for (var u = 0; u < defaultValue.length; u++) {
                        tmp += defaultValue[u].id + ",";
                    }
                }
                //针对多选的下拉-----end
                var s1 = "";
                var tc = 0;
                for (var m = 0; m < cols.length; m++) {
                    checked = tmp.indexOf("," + cols[m][0] + ",") >= 0;
                    s1 += "<dd><input type='checkbox' " + (checked ? "checked=true" : "") + "name='" + name + "' title='" + cols[m][1] + "' value='" + cols[m][0] + "' lay-skin='primary' ></dd>";
                    if (checked) {
                        tc++;
                    }
                }

                str += itemPre +
                    "                <div class='layui-select-title'>\n" +
                    "                    <input type='text' placeholder='" + (tc > 0 ? ("已选择" + tc + "项") : "请选择") + "' value='' readonly='' class='layui-input layui-unselect'><i class='layui-edge'></i>\n" +
                    "                </div>\n" +
                    "                <dl class='layui-anim layui-anim-upbit' style=''>" +
                    s1 +
                    "</dl>\n" +
                    itemTail;
            }
        }
        else if (type == 'radio') {
            options = "";
            for (var l = 0; l < cols.length; l++) {
                checked = (defaultValue == cols[l][0]);
                options += "<input type='radio' " + (checked ? "checked " : "") + " name='" + name + "' value='" + cols[l][0] + "' title='" + cols[l][1] + "' />";
            }
            str += itemPre +
                options + "\n" +
                itemTail;
        }
        else if (type == 'checkbox') {
            tmp = "," + defaultValue + ",";
            options = "";
            for (var k = 0; k < cols.length; k++) {
                checked = tmp.indexOf("," + cols[k][0] + ",") >= 0;
                options += "<input type='checkbox' " + (checked ? "checked=true" : "") + " name='" + name + "' value='" + cols[k][0] + "' lay-skin='primary' title='" + cols[k][1] + "' >";
            }
            str += itemPre +
                options + "\n" +
                itemTail;
        } else if (type == 'treeSelect') {
            str += itemPre +
                "<div id='" + id + "' type='" + type + "' name='" + name + "' class='layui-form-select select-tree bs-input-div'>\</div>" +
                itemTail;
        }
    }

    return str;
};


/**
 * 初始化多选下拉菜单, 在每次设置form之后调用
 */
var initSelect = function (pre, currentData) {
    $(pre + " .downpanel").on("click", ".layui-select-title", function (e) {
        var $select = $(this).parents(".layui-form-select");
        $(".layui-form-select").not($select).removeClass("layui-form-selected");
        if ($select.hasClass("layui-form-selected")) {
            $select.removeClass("layui-form-selected");
        }
        else {
            $select.addClass("layui-form-selected");
        }
        e.stopPropagation();
    }).on("click", ".layui-form-checkbox", function (e) {
        var count = 0;
        $(this).parent().parent().find('input:checkbox').each(function () {
            if ($(this).is(':checked')) {
                count++;
            }
        });
        $(this).parent().parent().parent().find('input:text').val('已选择' + count + '项');

        if (bsConf.hasOwnProperty("needCreateDataTypes")) {
            if ($(this).parent().parent().parent().attr('id') == "setDataTypes") {
                var current = $(this).parent().find('input:checkbox:first');
                var currentRoleId = current.val();
                if (current.is(':checked')) {
                    if ($(this).parent().parent().parent().attr('id') == "setDataTypes") {
                        if (showDataTypeLayer) {
                            currentRoles.push({"id": current.val(), "dataTypes": []});
                            showDataTypeLayer(current.val(), currentData);
                        }
                    }
                } else {
                    isExistInRole(currentRoleId);
                }
            }
        }
        e.stopPropagation();
    });

    //初始化时间控件
    $(pre + " .bs-datetime").each(function () {
        laydate.render({
            elem: "#" + $(this).attr('id')
            // , type: 'datetime'
            , show: false //直接显示
            , max: getNowFormatDate()
        });
    });
    $(pre + " .bs-datetimerange").each(function () {
        laydate.render({
            elem: "#" + $(this).attr('id')
            // , type: 'datetime'
            , show: false //直接显示
            , range: true
            , max: getNowFormatDate()
        });
    });
};

/**
 * 获取表单的值
 * @param v
 * @returns {string}
 */
var getInputValue = function (v) {
    var re = "";
    var type = v.attr('type');
    var multiple2 = v.attr('multiple2');
    if (type == 'checkbox' || (type == 'select' && multiple2 == 'true')) {
        v.find('input:checkbox').each(function () {
            if ($(this).is(':checked')) {
                re += (re == "" ? "" : ",") + $(this).val();
            }
        })
    }
    else if (type == 'radio') {
        v.find('input:radio').each(function () {
            if ($(this).is(':checked')) {
                re = $(this).val();
            }
        })
    }
    else if (type == 'select') {
        re = v.find('select').val();
        if (re != null && re.length > 0) {
            return re[0];
        }
    }
    else if (type == 'textarea') {
        re = v.find('textarea').val();
    }
    else {
        re = v.find('input').val();
    }
    return re;
};

var getStrFromDataMap = function (str) {
    if (isNull(str)) {
        return str;
    }
    while (true) {
        var from = str.indexOf("{{");
        if (from >= 0) {
            var to = str.indexOf("}}", from);
            if (to >= 0) {
                var tm = str.substr(from, to - from + 2);
                var ss = tm.substr(2, tm.length - 4).split("/");
                var v = dataMap;
                for (var x = 0; x < ss.length; x++) {
                    if (isNotNull(v)) {
                        v = v[ss[x]];
                    }
                    else {
                        v = "";
                    }
                }
                str = str.replaceAll(tm, v);
                continue;
            }
        }
        break;
    }
    return str;
};

/**
 * 显示弹出form
 * @param configs
 * @param formId    生成的form的id
 * @param submitUrl
 * @param callback  提交之后的callback
 */
var showLayer = function (currentData, configs, formId, submitUrl, callback) {
    initRoles(currentData);
    var str = "<div id=''>\n" +
        "    <form id='" + formId + "' class='layui-form bs-edit-form' style='padding: 20px;'>";
    str += createFormHtml(configs, false);
    str += "<div class='layui-form-item' style='padding: 5px;'>\n" +
        "            <div class='layui-input-block'>\n" +
        "                <button lay-submit lay-filter='" + formId + "' type='button' id='" + formId + "-sub-btn' class='layui-btn " + formId + "'  >立即提交</button>\n" +
        "                <button type='reset' class='layui-btn layui-btn-primary'>重置</button>\n" +
        "            </div>\n" +
        "        </div>";
    str += "</form></div>";
    layer.open({
        type: 1,
        content: str,
        area: ['70%', '70%'],
        success: function () {
            initSelect("#" + formId, currentData);
            if (bsConf.getTreeSelectData) {
                bsConf.getTreeSelectData(currentData);
            }
            bsConf[formId] = function () {
                var map = {};
                //创建参数，如果需要自定义，在自己的config中增加“createParam”参数
                if (bsConf.createParam) {
                    map = bsConf.createParam(formId);
                } else {
                    $('#' + formId + ' .bs-input-div').each(function () {
                        var name = $(this).attr('name');
                        map[name] = getInputValue($(this));
                    });
                }

                $.ajax({
                    type: 'post',
                    url: submitUrl,
                    contentType: "application/json; charset=utf-8",
                    headers:{"token":getCookie("token")},
                    dataType: 'json',
                    data: JSON.stringify(map),
                    success: function (result) {
                        checkLogin(result);
                        layer.msg(result.msg, {
                            time: 2000
                        }, function () {
                            if (result.code == 0) {
                                layer.closeAll();
                            }else{
                                document.getElementById(formId+"-sub-btn").removeAttribute("disabled");
                            }
                            if (isNotNull(callback)) {
                                callback(result);
                            }
                        });
                    }
                })
            }
        }
    });
    form.render();
};

var showCreateLayer = function () {
    layerMode = "create";
    showLayer(null, bsConf.createConfigs, bsConf.createFormId, url, function (result) {
        if (isNotNull(bsConf.createCallback)) {
            bsConf.createCallback(result);
        }
        queryData(url, pageObj.curr, pageObj.limit);
    });
};

var showUpdateLayer = function (currentData) {
    layerMode = "update";
    setConfigsAndShowLayer(currentData, bsConf.voName ? bsConf.voName : "vo", bsConf.updateConfigs, url + "/" + currentData[bsConf.tableID], null, function (result) {
        //自定义回调
        if (isNotNull(bsConf.updateCallback)) {
            bsConf.updateCallback(result);
        }
        queryData(url, pageObj.curr, pageObj.limit);
    });

};

var setConfigsAndShowLayer = function (currentData, objName, configs, updateUrl, dataCallback, doneCallback) {
    var confs = configs;
    if (null != dataCallback && dataCallback !== undefined) {
        confs = dataCallback(confs, result);
    } else {
        for (var i = 0; i < confs.length; i++) {
            var name = confs[i]['name'];
            if (isNotNull(name)) {
                confs[i]['default'] = currentData[name];
            }
        }
    }
    showLayer(currentData, confs, bsConf.updateFormId, updateUrl, function (result) {
        if (isNotNull(doneCallback)) {
            doneCallback(result);
        } else {
            queryData(url, pageObj.curr, pageObj.limit);
        }

    });
};


var deleteBatch = function () {
    var ids = getSelectedDataIds();
    if (ids.length > 0) {
        layer.confirm('确定要删除这些数据吗?', function (index) {
            var deleteUrl = url + "/remove";
            $.ajax({
                type: 'post',
                url: deleteUrl,
                contentType: 'application/json',
                headers:{"token":getCookie("token")},
                dataType: 'json',
                data: JSON.stringify({
                    "ids": ids
                }),
                success: function (result) {
                    checkLogin(result);
                    if(result.code !== 3000){
                        if (result.code !== 0) {
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 2000
                            });
                        } else {
                            layer.msg(result.msg, {
                                time: 2000
                            });
                            queryData(url, pageObj.curr, pageObj.limit);
                        }
                    }
                }
            });
            layer.close(index);
        });
    } else {
        layer.msg("请选择要删除的数据");
    }
};

var deleteCurrent = function (id) {
    layer.confirm('确定要删除这条数据吗?', function (index) {
        var deleteUrl = url + "/remove/" + id;
        $.ajax({
            type: 'post',
            url: deleteUrl,
            dataType: 'json',
            headers:{"token":getCookie("token")},
            success: function (result) {
                checkLogin(result);
                if (result.code !== 3000) {
                    if (result.code !== 0) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        });
                    } else {
                        queryData(url, pageObj.curr, pageObj.limit);
                    }
                }
            }
        });
        layer.close(index);
    });
};

var getSelectedData = function () {
    var checkStatus = table.checkStatus(bsConf.tableID);
    var selectedData = checkStatus.data;
    return selectedData;
};

var getSelectedDataIds = function () {
    var ids = [];
    var selectedData = getSelectedData();
    if (selectedData.length > 0) {
        for (var i = 0; i < selectedData.length; i++) {
            ids[i] = selectedData[i][bsConf.tableID];
        }
    }
    return ids;
};

var initRoles = function (currentData) {
    if (bsConf.hasOwnProperty("needCreateDataTypes")) {
        if (layerMode === "update") {
            if (currentData.hasOwnProperty("roles")) {
                currentRoles = currentData['roles'];
            }
        } else {
            currentRoles = [];
        }
    }

};

/**
 * 查询表单
 * @param url
 * @param pageNo
 * @param pageSize
 */
var initData = function () {
    //高度
    var height = $(window).height();
    var tableY = $('#tableDiv').offset().top;
    var data = {};
    var pageInfo = {};
    pageInfo.list = [];
    data.pageInfo = pageInfo;
    data.code = 0;
    data.msg = '成功';
    data.totalCount = 0;
    table.render({
        id: bsConf.tableID,
        elem: '#tableDiv'
        , height: height - tableY - 85
        //表格的列
        , cols: [bsConf.tableCols]
        , data: ['init']
        // , text:{none:'无'}

    });


};


$(function () {
    layui.use(['laypage', 'layer', 'table', 'form', 'util','laydate','element'], function () {
        table = layui.table;
        laypage = layui.laypage;
        layer = layui.layer;
        form = layui.form;
        util = layui.util;
        laydate = layui.laydate;
        element = layui.element;
        if(bsConf.queryConfigs){
            createQueryForm(bsConf.queryConfigs, bsConf.queryFormId);
        }
        form.render();
        //默认不查询
        if (bsConf.initData) {
            initData();
        } else {
            queryData(url, 1, 20);
        }
        // queryData(url, 1, 20);
        bindTableEventCol();
        if(bsConf.needChangeTab){
            bsConf.changeTab();
        }
        if(bsConf.needInitECharts){
            bsConf.initECharts();
        }
    });
    bindButtonEvents();
    enableBtns();
    $("input").click(function () {
        //获取checkbox选中项
        if ($(this).prop("checked") == true) {
            $(this).parent().parent().css("background", "#b2dba1");
        } else {
            $(this).parent().parent().css("background", "");
        }
    });
});

var enableBtns = function () {
    var pageId = getUrlParam("pageId");
    if(pageId && bsConf.enableBtns){
        //var buttons = [{id:'id1',alias:'updateBiz',forbiddenType:'disable'},{id:'id2',alias:'noProcessed',forbiddenType:'hidden'}];
       var url = authApiPrefix+"/page/buttons?pageId="+pageId;
        $.ajax({
            type: 'get',
            headers: {"token": getCookie("token")},
            url: url,
            success: function (result) {
                if (result.code == 0) {
                    var buttons = result.data.buttons;
                    for (var i = 0; i < buttons.length; i++) {
                        var button = buttons[i];
                        var id = '#' + button['alias'];
                        var currentBtn = $(id);
                        if (currentBtn) {
                            $(id).removeClass("layui-btn-disabled");
                        }
                    }
                }
            }
        });
    }
};


function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + " " + date.getHours() + seperator2 + date.getMinutes()
        + seperator2 + date.getSeconds();
    return currentdate;
}